// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
    env:'mupp-5gs2863z7cf6873f'
})

// 云函数入口函数
exports.main = async (event, context) => {
    const wxContext = cloud.getWXContext()
    const shop=cloud.database().collection('shop')
    console.log(event)
    let index=event.index
    let openid=wxContext.OPENID
    let res=await shop.where({
        _id:event._id
    }).get()
    console.log('res',res)
    let all=res.data[0].all
    if(event.change){
        all[index][1].push(openid)
    }else{
        all[index][1].splice(all[index][1].indexOf(openid),1)
    }
    console.log('all',all)
    shop.where({
        _id:event._id
    }).update({
        data:{
            all,
        }
    })
    
    return {
        
    }
}